package Month10.day1003;

public class Student implements Cloneable{
    String name;//每个学生都有自己的名字
    int age;//每个学生都有自己的年龄
    Sport spo;//每个学生都有自己喜欢的运动

    public Student(String name, int age, Sport spo) {
        this.name = name;
        this.age = age;
        this.spo = spo;
    }

    @Override
    public Student clone() throws CloneNotSupportedException {
        Student key = (Student) super.clone();//首先克隆当前对象
        key.spo = spo.clone();//在接着克隆原来对象当中的Sport成员
        return key;
    }

    public static void main(String[] args) throws CloneNotSupportedException{
        Student s1 = new Student("李明",3,new Sport(1));
        Student s2 = s1.clone();
        s2.spo.sum = 22;
        System.out.println(s1.spo.sum);
    }
}

